<template>
	<view class="content">
		<!--
		* 广告组件
		* timedown 倒计时时间
		* imageUrl 背景图
		* url 跳转链接
		*  -->

		<!-- 下拉刷新组件 -->
		<view class="" v-for="(item, index) in Branchs" :key="index">
			<uni-card :title="item.BranchName" @click="goMember(item.BranchCode, item.Brief)" :thumbnail="item.PhotoUrl"
				mode="style">
				<text>{{item.Brief}}</text>
			</uni-card>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex';
	export default {
		onShow() {
			uni.setNavigationBarTitle({
				title: "之江党支部-信息"
			})
			this.loadTabbarList()

		},
		components: {},
		data() {
			return {
				Branchs: [],
				tabBarList: [

				]
			};
		},
		activated() {
			// uni.reloadpage()
			console.log("activated")
			this.loadBranchs();
			this.loadTabbarList()
		},
		computed: {
			...mapState(['token', 'userCode'])
		},
		async onLoad() {
			this.loadBranchs();
			this.loadTabbarList()
			// this.hasLogin();
			// 获取屏幕宽度
		},
		onReady() {
			console.log("onReady")
			// console.log('aa');
			uni.showShareMenu({
				success: (e) => {
					console.log(e);
				},
				fail: (e) => {
					console.log(e);
				}
			})
		},
		methods: {
			...mapActions(['reLogin', 'getToken', 'hasLogin']),
			reloadpage() {
				location.reload();
			},
			/**
			 * 数据处理方法在vue和nvue中通用，可以直接用mixin混合
			 * 这里直接写的
			 * mixin使用方法看index.nuve
			 */
			goMember(branchCode, text) {
				uni.navigateTo({
					url: `/pages/branchMember/branchMember?branchCode=${branchCode}&text=${text}`,
					fail: e => {
						console.log(e);
					}
				});
			},
			//获取分类
			loadBranchs() {
				uni.showLoading()
				this.$request.httpRequest({
					url: `/api/Branch?userCode=${this.userCode}&token=${this.token}`
				}, {}).then(e => {
					if (!e.data.Success) {
						this.reLogin();
					}
					this.Branchs = e.data.items;
					uni.hideLoading()
				}).catch(e => {
					this.reLogin();
				})
			},
			loadTabbarList: function() {
				this.$request.httpRequest({
					url: `/api/GetIcon`
				}, {
					userCode: this.userCode,
					token: this.token
				}).then(e => {
					if (!e.data.Success) {
						this.reLogin();
					}
					this.tabBarList = e.data.iconInfos
					// console.log(this.tabBarList);
					this.tabBarList.forEach((item, index) => {
						uni.setTabBarItem({
							index: index,
							text: item.IconName,
							iconPath: item.PicIcon,
							selectedIconPath: item.PicIcon
						})
					})
				}).catch(e => {
					this.reLogin();
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	page,
	.content {
		background-color: #f8f8f8;
		/* height: 100%; */
		overflow: hidden;
	}

	.uni-grid-item {
		height: 100% !important;
	}
</style>
